Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(exex): finalize WAL only when all ExExes are on the canonical chain #11289

Merged
merged 8 commits into from
Sep 29, 2024

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Sep 27, 2024

Towards #11262

Calls Wal::finalize only when all ExExes are on the canonical chain, according to the last emitted FinishedHeight, so we're sure that we will not delete any notifications that may be necessary for reverting to the canonical chain from a fork.

@shekhirin shekhirin added C-enhancement New feature or request A-exex Execution Extensions labels Sep 27, 2024
@shekhirin shekhirin changed the title feat(exex): finalize WAL when only all ExExes are on the canonical chain feat(exex): finalize WAL only when all ExExes are on the canonical chain Sep 27, 2024
@shekhirin shekhirin marked this pull request as ready for review September 27, 2024 14:47
Comment on lines 341 to 365
debug!(header = ?header.num_hash(), "Received finalized header");

// Check if all ExExes are on the canonical chain
let exex_finished_heights = this
.exex_handles
.iter()
// Get ExEx ID and hash of the finished height for each ExEx
.map(|exex_handle| {
(&exex_handle.id, exex_handle.finished_height.map(|block| block.hash))
})
// Deduplicate all hashes
.unique_by(|(_, hash)| *hash)
// Check if hashes are canonical
.map(|(exex_id, hash)| {
hash.map_or(Ok((exex_id, hash, false)), |hash| {
this.provider
.header(&hash)
// Save the ExEx ID, hash of the finished height, and whether the hash
// is canonical
.map(|header| (exex_id, Some(hash), header.is_some()))
})
})
.collect::<Result<Vec<_>, _>>()?;
if exex_finished_heights.iter().all(|(_, _, is_canonical)| *is_canonical) {
// If there is a finalized header and all ExExs are on the canonical chain, finalize
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very hard to read now, this entire poll function is massive, can we please split this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair, moved to a separate fn

.filter_map(|(exex_id, hash, is_canonical)| {
is_canonical.not().then_some((exex_id, hash))
})
.collect::<Vec<_>>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this collect is redundant, itertools has helper for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the collect is for debug logging below

let unfinalized_exexes = exex_finished_heights
.into_iter()
.filter_map(|(exex_id, hash, is_canonical)| {
is_canonical.not().then_some((exex_id, hash))
})
.collect::<Vec<_>>();
debug!(
?unfinalized_exexes,
"Not all ExExes are on the canonical chain, can't finalize the WAL"
);

crates/exex/exex/src/manager.rs Show resolved Hide resolved
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, one suggestion

.filter_map(|(exex_id, hash, is_canonical)| {
is_canonical.not().then_some((exex_id, hash))
})
.collect::<Vec<_>>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I meant was this is redundant because only used for debug trace and we now have access to

https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.format

let this = self.get_mut();

// Handle incoming ExEx events
for exex in &mut this.exex_handles {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we actually spawn the manager if there are 0 exexs?

if we do, then we need a shortcut because otherwise we do unnecessary wal IO?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't spawn it if there are no ExExes

@shekhirin shekhirin added this pull request to the merge queue Sep 29, 2024
Merged via the queue into main with commit ce1f669 Sep 29, 2024
36 checks passed
@shekhirin shekhirin deleted the alexey/exex-wal-finalize-only-all-canonical branch September 29, 2024 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exex Execution Extensions C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants